package vip.xiaonuo.invoice.core.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

/**
 * 任务调度器配置类
 */
@Configuration
public class TaskSchedulerConfig {
    /**
     * 配置ThreadPoolTaskScheduler bean
     * @return ThreadPoolTaskScheduler实例
     */
    @Bean
    public ThreadPoolTaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
        // 设置线程池大小
        taskScheduler.setPoolSize(5);
        // 设置线程名称前缀
        taskScheduler.setThreadNamePrefix("invoice-callback-scheduler-");
        // 设置线程存活时间
        taskScheduler.setAwaitTerminationSeconds(60);
        // 初始化调度器
        taskScheduler.initialize();
        return taskScheduler;
    }

}
